# ******** Master File for the paper "Firm Quality Dynamics and the Slippery Slope of Credit Intervention" *******
# This files calls all other files and generate all figures in the paper. 
remove(list=ls())
parent_path = dirname(rstudioapi::getActiveDocumentContext()$path)
model_path = paste0(parent_path,"/Model files")
FigurePath = paste0(parent_path,"/Figures")
setwd(model_path)

# ------- Load required packages and self-defined functions -------
source("package_function_and_path.R")

# ------- Main figures and tables -------
# Main Figures 1-7, Appendix figure A1-A4, Main Table 1-2
source("Model.R")
# Main Figure 8, Case with pure subsidy (Section 3.4). Appendix figure A14 for Appendix D.4.
source("Model-with subsidy.R")

# ------- Appendix figures from model analysis -------
# Figure A7, A8, and A9. (Appendix Section D.1, impact of firm entry)
source("Model-with larger eta.R")

# Figure A10, A11, and A12. (Appendix Section D.2, impact of firm-type transitions)
source("Model-with type transition.R")

# Figure A13 (Appendix D.3, alternative policy goals)
source("Model-contain capital drop.R")

# Figure A15-A16 (Appendix D.5, extension of different liquidity crisis)
source("Model-with recovery kappax.R")

# ------- Appendix figures/tables from data analysis -------
# Then call the data analysis file to generate data-related plots 
setwd( paste0(parent_path,"/Firm Quality Data Analysis/") )
# Figure A6, Table A1
source("code/3.Test_TFP_FinancialConstraint.R")
# Figure A5
source("code/4.TFP_plots.R")





